﻿/*****************************************************************************  

 Version: 0.1
 Website: http://www.visuagile.com/
 
 Copyright (c) Yoganand R. All rights reserved.
 For continued development and updates, visit http://yogsbreath.net
 
 ******************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VisualAgile.Model;

namespace VisualAgile.DTO.Mappers
{
    public class UserDTOMapper:BaseDTOMapper
    {
        public static UserDTO MapToDTO(User  model, bool includeFeelings)
        {
            IList<FeelingsDTO> feelingsDTO = new List<FeelingsDTO>();

            UserDTO dto = new UserDTO();
            dto.UserID = model.UserID;
            dto.ID = model.UserID.ToString();
            dto.Name = model.UserName;           
            dto.Mobile = model.Mobile;
            dto.Telephone = model.Telephone;
            dto.ValidFrom = model.ValidFrom;
            dto.ValidTo = model.ValidTo;          
            dto.Email = model.Email;
            dto.CreateDate = model.CreateTime;
            dto.Role = model.Role == null ? "" : model.Role.Name;

            if (includeFeelings)
            {
                //load features
                foreach (Feelings feeling in model.Feelings)
                {
                    feelingsDTO.Add(FeelingsDTOMapper.MapToDTO(feeling));
                }
                dto.feelings = feelingsDTO;
            }

            return dto;
        }
        public static User MapFromDTO(UserDTO dto)
        {
            User user = new User();
            user.UserID = dto.UserID;
            user.Role = (dto.RoleID == null) ? null : ManagerFactory.RoleManager.GetById(dto.RoleID);
            user.UserName = dto.Name;            
            user.Mobile = dto.Mobile;
            user.Telephone = dto.Telephone;
            user.ValidFrom = dto.ValidFrom;
            user.ValidTo = dto.ValidTo;                      
            user.Email = dto.Email;
            user.CreateTime = DateTime.Now;
            return user;
        }
    }
}
 